import * as echarts from 'echarts';
import vueSeamlessScroll from "vue-seamless-scroll";
import Danger from '@/pages/number-screen/components/Danger'
import NoWorkElectricity from '@/pages/number-screen/components/NoWorkElectricity'
import IntelligenceElectrokinesis from '@/pages/number-screen/components/IntelligenceElectrokinesis'
import EventLog from '@/pages/number-screen/components/EventLog'
import DataStatistics from '@/pages/number-screen/components/DataStatistics'
import SafeOperation from '@/pages/number-screen/components/SafeOperation'
import Abnormal from '@/pages/number-screen/components/Abnormal'
import ElectricityConsumption from '@/pages/number-screen/components/ElectricityConsumption'
import DeviceStatus from '@/pages/number-screen/components/DeviceStatus'
import ElectricityConsumptionTable from '@/pages/number-screen/components/ElectricityConsumptionTable'
import DangerTable from '@/pages/number-screen/components/DangerTable'
import NoWorkElectricityTable from '@/pages/number-screen/components/NoWorkElectricityTable'
import ajax from "@/utils/ajax";

export default {

  data() {
    return {
      querytime: "",
      queryTimeValue: new Date(),
      queryregion: "",
      data: [],
      params: {
        page: 1,
        size: 10
      },
      total: 10,
      radio1: 1,
      tableActive: "first",
      centerOutletsOptions: [
        {
          //网点下拉
          value: 1,
          label: "丰泽新秀社区"
        },
        {
          value: 2,
          label: "泉州银行泉秀支行"
        },
        {
          value: 3,
          label: "泉州大洋百货"
        },
        {
          value: 4,
          label: "幸福大厦"
        },
        {
          value: 5,
          label: "中心客运站"
        }
      ],
  

    };
  },
  components: {
    vueSeamlessScroll, Danger, IntelligenceElectrokinesis, NoWorkElectricity, EventLog, DataStatistics, SafeOperation,
    Abnormal, ElectricityConsumption, DeviceStatus, ElectricityConsumptionTable, DangerTable, NoWorkElectricityTable
  },
  created() {
    this.querytime =getFormatDate(this.queryTimeValue).slice(0, 10) 
  },
  mounted() {
    this.$store.dispatch('actions/dynamicTitleAction', this.$route.meta.title)
   this.getUserManagerBranch()
  },
  computed: {
    defaultOption() {
      return {
        step: 0.2 // 数值越大速度滚动越快
      };
    }
  },
  methods: {
    //隐患图表 后期加请求动态修改
    dangerShow: function (type) {
 
      this.tableActive = type[0];
      this.queryregion=parseInt(type[1])
    },
    //非工作时间 后期加请求动态修改
    noworkelectricityShow: function (type) {
      this.tableActive = type[0];
      this.queryregion=parseInt(type[1])
    },
    electricityconsumptionShow: function (type) {
    
      this.tableActive = type[0];
    },
    timeBlur: function (e) {
      let self = this
      // console.log(self.queryTimeValue)
      self.querytime = self.queryTimeValue != null ? getFormatDate(self.queryTimeValue) : ''
      // console.log(self.querytime)
    },
    Query: function () {
      let self = this
      // console.log(self.queryTimeValue)
      self.querytime = self.queryTimeValue != null ? getFormatDate(self.queryTimeValue) : ''
      
      switch (self.tableActive) {
        case 'first':
          self.$refs.ElectricityConsumptionTable.querytTable(self.querytime, self.queryregion)
          break
      }
    },
    getUserManagerBranch() {
      ajax.get({
        url: this.$API.getUserManagerBranch,
        data: {},
        success: (response) => {
          let self = this;
          // console.log(self.queryregion)
          self.centerOutletsOptions = response.data;
          self.queryregion=parseInt(response.data[0].branchId)
          // console.log(self.queryregion)

        },
      });
    },
  },
  beforeDestroy() {

  },
};

function getFormatDate(nowDate) {
  let date = nowDate
  let month = date.getMonth() + 1
  let strDate = date.getDate()
  let hours = date.getHours()
  let minutes = date.getMinutes()
  let seconds = date.getSeconds()
  if (month >= 1 && month <= 9) {
    month = '0' + month
  }
  if (strDate < 10) {
    strDate = '0' + strDate
  }
  if (hours < 10) {
    hours = '0' + hours
  }
  if (minutes < 10) {
    minutes = '0' + minutes
  }
  if (seconds < 10) {
    seconds = '0' + seconds
  }
  let currentDate = date.getFullYear() + '-' + month + '-' + strDate + ' ' + hours + ':' + minutes + ':' + seconds
  // console.log(currentDate)
  return currentDate
}
